home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 5.9 KB | 279 lines | [TEXT/MPS ] |
- /*
- File: VirtualMacFile.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __VIRTUALMACFILE__
- #include "VirtualMacFile.h"
- #endif
-
- #ifndef __VIRTUALFILE__
- #include "VirtualFile.h"
- #endif
-
- #ifndef __VIRTUALHFSMACFILE__
- #include "VirtualHFSMacFile.h"
- #endif
-
- #ifndef __DEBUGGINGGEAR__
- #include "DebuggingGear.h"
- #endif
-
- #ifndef __VVFILEMACFILE__
- #include "VVFileMacFile.h"
- #endif
-
- /***********************************|****************************************/
-
- #pragma segment VirtualMacFile
-
- /***********************************|****************************************/
-
- ostream& TVirtualMacFile::operator >> ( ostream& s ) const
- {
- return s << "TVirtualMacFile @ " << ( void*) this;
- }
-
- //--------------------------------------------------------------------------------
-
- TVirtualMacFile::TVirtualMacFile():
- THandleObject ()
- {
- }
-
- //--------------------------------------------------------------------------------
-
- TVirtualMacFile::TVirtualMacFile( const TVirtualMacFile& that ):
- THandleObject ( that )
- {
- }
-
- //--------------------------------------------------------------------------------
-
- TVirtualMacFile::~TVirtualMacFile()
- {
- }
-
- /***********************************|****************************************/
-
- TVirtualMacFile&
- TVirtualMacFile::operator = ( const TVirtualMacFile& that )
- {
- THandleObject::operator = ( that );
- return *this;
- }
-
- /***********************************|****************************************/
-
- OSErr
- TVirtualMacFile::WriteToDisk ()
- {
- FSSpec spec;
- GetSpec ( spec );
- return WriteToDisk ( spec );
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualMacFile::WriteToDisk ( const FSSpec& storage )
- {
- TVirtualMacFile* tempFile = new TVirtualHFSMacFile ( storage );
-
- if ( !tempFile )
- return memFullErr;
-
- OSErr error = tempFile->Open ();
-
- if ( !error )
- error = Copy ( tempFile );
-
- tempFile->Close();
-
- delete tempFile;
-
- return error;
- }
-
- /***********************************|****************************************/
-
- OSErr
- TVirtualMacFile::CopyFork ( TVirtualMacFile::ForkType fork, TVirtualMacFile* destination )
- {
- const unsigned long kBufferSize = 1024;
- long fileSize, origPosition;
-
- OSErr error = GetEnd ( fileSize, fork );
-
- if ( error )
- return error;
-
- error = GetPosition ( origPosition, fork );
-
- if ( error )
- return error;
-
- error = SetPosition ( fsFromStart, 0, fork );
-
- if ( error )
- return error;
-
- error = destination->SetEnd ( 0, fork );
-
- if ( error )
- return error;
-
- error = destination->SetPosition ( fsFromStart, 0, fork );
-
- if ( error )
- return error;
-
- if ( fileSize > 0 )
- {
- Ptr buffer = FAILNewPtr ( kBufferSize );
-
- TRY
- {
- do
- {
- long chunkSize = fileSize > kBufferSize ? kBufferSize : fileSize;
- error = ReadData ( buffer, chunkSize, fork );
-
- if ( !error )
- error = destination->WriteData ( buffer, chunkSize, fork );
-
- fileSize -= chunkSize;
- }
- while ( !error && fileSize > 0 );
- }
- EXCEPTION
- {
- }
- ENDEXCEPTION
-
- DeallocatePtr ( buffer );
- }
-
- SetPosition ( fsFromStart, origPosition, fork );
-
- return error;
- }
-
- /***********************************|****************************************/
-
- OSErr
- TVirtualMacFile::Copy ( TVirtualMacFile* destination )
- {
- OSErr error = CopyFork ( TVirtualMacFile::kData, destination );
-
- if ( error )
- return error;
-
- error = CopyFork ( TVirtualMacFile::kResource, destination );
-
- if ( error )
- return error;
-
- FInfo finderInfo;
- error = GetFinderInfo ( finderInfo );
-
- if ( error )
- return error;
-
- error = destination->SetFinderInfo ( finderInfo );
-
- if ( error )
- return error;
-
- destination->SetUserRef ( GetUserRef () );
-
- return error;
- }
-
- /***********************************|****************************************/
-
- TVirtualMacFile*
- TVirtualMacFile::Clone ()
- {
- Str31 fileName;
- GetFileName ( fileName );
- TVVFileMacFile* destination = new TVVFileMacFile ( fileName );
- destination->Open ();
- Copy ( destination );
- destination->Close ();
- return destination;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualMacFile::GetFileInfo ( FSSpec& spec, HParamBlockRec& paramBlock )
- {
- paramBlock.fileParam.ioVRefNum = spec.vRefNum;
- paramBlock.fileParam.ioDirID = spec.parID;
- paramBlock.fileParam.ioFDirIndex = 0;
- paramBlock.fileParam.ioNamePtr = spec.name;
- return PBHGetFInfo ( ¶mBlock, false );
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualMacFile::SetFileInfo ( FSSpec& spec, HParamBlockRec& paramBlock )
- {
- paramBlock.fileParam.ioVRefNum = spec.vRefNum;
- paramBlock.fileParam.ioDirID = spec.parID;
- paramBlock.fileParam.ioFDirIndex = 0;
- paramBlock.fileParam.ioNamePtr = spec.name;
- return PBHSetFInfo ( ¶mBlock, false );
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualMacFile::SetFileName(const Str31 name)
- {
- FSSpec spec;
- OSErr error = GetSpec ( spec );
- PLstrcpy ( spec.name, name );
- return SetSpec ( spec );
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualMacFile::GetFileName(Str31 name) const
- {
- FSSpec spec;
- OSErr error = GetSpec ( spec );
- PLstrcpy(name,spec.name);
- return error;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr ChangeFileDates(const FSSpec& orig, long modDate, long creationDate)
- {
- FSSpec spec = orig;
- HParamBlockRec paramBlock;
- OSErr err = TVirtualMacFile::GetFileInfo ( spec, paramBlock );
-
- if ( err )
- return err;
-
- paramBlock.fileParam.ioDirID = spec.parID;
- paramBlock.fileParam.ioFlCrDat = creationDate;
- paramBlock.fileParam.ioFlMdDat = modDate;
-
- return TVirtualMacFile::SetFileInfo ( spec, paramBlock );
- }
-
- /***********************************|****************************************/
-